﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MachineBuildingSystem
{
    public partial class ActionForm : XtraForm
    {
        //是否新增
        private bool m_IsAdd = true;
        public bool IsAdd
        {
            get { return m_IsAdd; }
            set { m_IsAdd = value; }
        }

        //名称
        private string m_Name = "";
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        //新名称
        private string m_NewName = "";
        public string NewName
        {
            get { return m_NewName; }
            set { m_NewName = value; }
        }

        private List<string> m_NameList = new List<string>();
        public List<string> NameList
        {
            get { return m_NameList; }
            set { m_NameList = value; }
        }

        public ActionForm()
        {
            InitializeComponent();
        }

        private void ActionAddForm_Load(object sender, EventArgs e)
        {
            if (m_IsAdd)
            {
                txtName.Properties.ReadOnly = false;
                lciNewName.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                this.Text = "新增";
            }
            else
            {
                txtName.Properties.ReadOnly = true;
                lciNewName.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
                txtName.Text = m_Name;
                this.Text = "修改";
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (m_IsAdd)
            {
                m_Name = this.txtName.Text.Trim();
                if (string.IsNullOrEmpty(m_Name))
                {
                    MessageBox.Show(this, "名称不能为空！");
                    return;
                }
                if (m_NameList.Contains(m_Name))
                {
                    MessageBox.Show(this, "新增时名称不能重复！");
                    return;
                }
            }
            else
            {
                m_NewName = this.txtNewName.Text.Trim();
                if (string.IsNullOrEmpty(m_NewName))
                {
                    MessageBox.Show(this, "名称不能为空！");
                    return;
                }
                if (m_NameList.Contains(m_NewName) && m_NewName != this.txtName.Text.Trim())
                {
                    MessageBox.Show(this, "新增时名称不能重复！");
                    return;
                }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
